package com.qianyu.project.mapper.provider.sy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

public class ContractReceiptProvider {

    public String getList(IPage page, Map<String, String> params){
        return new SQL(){
            {
                SELECT("r.*, p.project_name, i.contract_name, t.company_name, i.contract_amount");
                FROM("contract_receipt r, project_info p, income_contract i, tender_company t");
                WHERE("r.pid = p.id and r.ctr_id = i.id and r.company_id = t.id");
                if(StringUtils.hasLength(params.get("id"))){
                    WHERE(" r.id = #{params.id}");
                }
                if(StringUtils.hasLength(params.get("receiptName"))){
                    WHERE(" r.receipt_name like '%${params.receiptName}%'");
                }
                if(StringUtils.hasLength(params.get("pid"))){
                    WHERE(" r.pid = #{params.pid}");
                }
                if (StringUtils.hasLength(params.get("approveStatus"))){
                    WHERE(" r.approve_status = #{params.approveStatus}");
                }
                if (StringUtils.hasLength(params.get("ctrId"))){
                    WHERE(" r.ctr_id = #{params.ctrId}");
                }
                if (StringUtils.hasLength(params.get("applyer"))){
                    WHERE(" r.applyer like '%${params.applyer}%'");
                }
                if(StringUtils.hasLength(params.get("applyDate1")) && StringUtils.hasLength(params.get("applyDate2"))){
                    WHERE(" r.apply_date >= '${params.applyDate1}' and r.apply_date <= '${params.applyDate2}'");
                }
                if(StringUtils.hasLength(params.get("companyId"))){
                    WHERE(" r.company_id = #{params.companyId}");
                }
            }
        }.toString();
    }

    public String getOne(String id){
        return new SQL(){
            {
                SELECT("r.*, p.project_name, i.contract_name, t.company_name, i.contract_amount");
                FROM("contract_receipt r, project_info p, income_contract i, tender_company t");
                WHERE("r.pid = p.id and r.ctr_id = i.id and r.company_id = t.id and r.id = #{id}");
            }
        }.toString();
    }

}
